package com.lwp;

import com.lwp.domain.User;
import com.lwp.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * TestService
 *
 * @author lanwenping
 * @version 1.0
 * @date 2020/6/6 13:30
 */
@Service
public class TestService {

    @Autowired
    UserMapper userMapper;

    @Transactional
    public void updateUser() {

        User user = userMapper.selectByPrimaryKey(1L);
        user.setAge(22);
        userMapper.updateByPrimaryKey(user);
    }

    @Transactional
    public void updateUser1() {

        if (true) throw new RuntimeException("异常");
        User user = userMapper.selectByPrimaryKey(1L);
        user.setAge(22);
        userMapper.updateByPrimaryKey(user);
    }

    @Transactional
    public void updateUser2() {

        User user = userMapper.selectByPrimaryKey(1L);
        user.setAge(33);
        userMapper.updateByPrimaryKey(user);

        this.updateUser1();
    }
}
